package com.guigu.buy.controller;

import com.github.pagehelper.PageInfo;
import com.guigu.buy.dto.Storage_Detail;
import com.guigu.buy.dto.Storage_Stock;
import com.guigu.buy.mapper.StorageMapper;
import com.guigu.buy.pojo.PurchaseOrder;
import com.guigu.buy.pojo.StockDetails;
import com.guigu.buy.pojo.Storage;
import com.guigu.buy.service.IPurchaseOrderService;
import com.guigu.buy.service.IStockDetailsService;
import com.guigu.buy.service.IStorageService;
import com.guigu.buy.utils.FileAddUtil;
import com.guigu.buy.vo.StorageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author com.guigu
 * @since 2024-05-15
 */
@CrossOrigin
@Controller
@RequestMapping("/buy/storage")
public class StorageController {
    @Autowired
    private FileAddUtil addUtil;
    @Autowired
    private IStorageService storageService;
    @Autowired
    private StorageMapper storageMapper;
    @Autowired
    private IStockDetailsService stockDetailsService;
    //添加入库及明细
    @RequestMapping("/addStorage/{id}")
    @ResponseBody
    public String addStorage(@RequestBody Storage_Detail storage_detail,
                             @PathVariable int id){
        storage_detail.setStorageId(addUtil.getTypeNumber("300"));
        return storageService.addStorage(storage_detail,id);
    }
    @RequestMapping("/queryAll/{pageSize}/{pageNo}")
    @ResponseBody
    public PageInfo<Storage_Stock> queryAll(@PathVariable int pageSize,
                                            @PathVariable int pageNo,
                                            @RequestBody StorageVo vo){
        return storageService.queryAll(pageNo,pageSize,vo);
    }
    @RequestMapping("/getOne/{id}")
    @ResponseBody
    public Storage_Stock getOne(@PathVariable int id){
        return storageMapper.getOne(id);
    }
    @RequestMapping("/audit")
    @ResponseBody
    public boolean audit(@RequestBody Storage_Detail storage_detail){
        System.out.println(storage_detail);
        if (storage_detail.getList()==null){
            return false;
        }
        stockDetailsService.add(storage_detail.getList());
        return storageService.updateById(storage_detail);
    }
}
